﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace last.fm
{
	public static class User
	{
		public static String getLovedTracks(String user, Int32 limit, Int32 page)
		{
			KeyValuePair<String, String> methodvalue = new KeyValuePair<string, string>("method", "user.getlovedtracks");
			KeyValuePair<String, String> uservalue = new KeyValuePair<string, string>("user", user);
			KeyValuePair<String, String> tokenvalue = new KeyValuePair<string, string>("api_key", LastFmWebservice.apiKey);
			KeyValuePair<String, String> limitvalue = new KeyValuePair<string, string>("limit", limit.ToString());
			KeyValuePair<String, String> pagevalue = new KeyValuePair<string, string>("page", page.ToString());
			XElement resultXML = LastFmWebservice.Request(methodvalue, uservalue, tokenvalue, limitvalue, pagevalue);
			String output = "";
			if (resultXML.Attribute("status").Value == "ok")
			{
				IEnumerable<XElement> tracks = resultXML.Element("lovedtracks").Elements("track");
				foreach (XElement track in tracks)
				{
					output += track.Element("artist").Element("name").Value + " - " + track.Element("name").Value + "\n";
				}
				return output;
			}
			else
			{
				return null;
			}
		}
	}
}
